package pro.uccs.util;

import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import pro.uccs.constant.OpenPlatformConstant;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**********************************************************
 * Copyright © 2017,北京世纪奥通科技有限公司
 * All Rights Reserved.
 *
 * 文件名称： ${file_name}
 * 摘    要： [简要描述本文件的内容]
 *
 * 初始版本：1.0.0
 * 原 作 者：huangjing
 * 完成日期： 2018/10/10 0010

 * 当前版本： 1.0.0
 * 作    者： huangjing
 * 完成日期： 2018/10/10 0010
 *
 *****************************************************************/
public class MethodUtil {
    public static Map<String, String> getIsFriendParam(String userNumber ) throws IOException {
        String method = "simba.friend.isFriend";
        String clientId = OpenPlatformConstant.CLIENT_ID;
        Map<String, String> params = getCommonParam();
        params.put("friendNumber", userNumber);
        params.put("method", method);
        String sign = EncryptUtil.paramSign(params, OpenPlatformConstant.CLIENT_SECRET, Coder.KEY_MD5);
        params.put("sign", sign);
        return params;
    }
    public static Map<String, String> getPublicParam(String userNumber ) throws IOException {
        String method = "simba.user.public";
        String clientId = OpenPlatformConstant.CLIENT_ID;
        Map<String, String> params = getCommonParam();
        params.put("clientId", clientId);
        params.put("account", userNumber);
        params.put("method", method);
        String sign = EncryptUtil.paramSign(params, OpenPlatformConstant.CLIENT_SECRET, Coder.KEY_MD5);
        params.put("sign", sign);
        return params;
    }
    public static Map<String, String> getFriendApplyParam(String userNumber , String friendNumber) throws IOException {

        String method = "simba.friend.apply";
        String clientId = OpenPlatformConstant.CLIENT_ID;
        Map<String, String> params = getCommonParam();

        String param_json = "param_json={\"friendGroupBuddyVo\":{\"userNumber\":"+userNumber+",\"friendNumber\":"+friendNumber+",\"fgroupId\":0}}";
        params.put("param_json", param_json);
        params.put("method", method);
        String sign = EncryptUtil.paramSign(params, OpenPlatformConstant.CLIENT_SECRET, Coder.KEY_MD5);
        params.put("sign", sign);
        return params;
    }
    public static Map<String,String> getCommonParam(){
        Map<String, String> params = new HashMap<>();

        params.put("client_id", OpenPlatformConstant.CLIENT_ID);
        params.put("session", OpenPlatformConstant.SESSION);

        String timestamp = String.valueOf(System.currentTimeMillis());
        params.put("timestamp", timestamp);
        return params;
    }
}
